/*******************************************************************************
 * Copyright 2020 huanggefan.cn
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

const tools = require("../js/tools");

window.Action_UserInfo_GetUUID = function (account) {
    let request = tools.DeepCopy(window.API_Request_UserInfo_GetUserUUID);
    request.WillGetAccount = account;
    request.AuthToken = window.AuthToken;

    let requestLoad = JSON.stringify(request);

    return tools.XHR(
        "POST",
        window.API_HOST_SCHEMES,
        window.API_HOST_HOST,
        window.API_URL_UserInfo_GetUserUUID,
        requestLoad
    );
};

window.Action_UserInfo_Login = function (account, password) {
    let request = tools.DeepCopy(window.API_Request_UserInfo_Login);
    request.AccountID = account;
    request.PasswordMD5 = tools.MD5(password);

    let requestLoad = JSON.stringify(request);

    return tools.XHR(
        "POST",
        window.API_HOST_SCHEMES,
        window.API_HOST_HOST,
        window.API_URL_UserInfo_Login,
        requestLoad
    );
};

window.Action_UserInfo_ResetPassword = function (account) {
    let request = tools.DeepCopy(window.API_Request_UserInfo_ResetPassword);
    request.WillChangeAccountID = account;
    request.AuthToken = window.AuthToken;

    let requestLoad = JSON.stringify(request);

    return tools.XHR(
        "POST",
        window.API_HOST_SCHEMES,
        window.API_HOST_HOST,
        window.API_URL_UserInfo_ResetPassword,
        requestLoad
    );
};

window.Action_UserInfo_SignUp = function (account, password, passwordVerify, collegeUUID, majorUUID, classUUID, roleType) {
    let request = tools.DeepCopy(window.API_Request_UserInfo_SignUp);
    request.AccountID = account;
    request.PasswordMD5 = tools.MD5(password);
    request.PasswordVerifyMd5 = tools.MD5(passwordVerify);
    request.CollegeUUID = collegeUUID;
    request.DisciplineUUID = majorUUID;
    request.ClassUUID = classUUID;
    request.RoleType = roleType;
    request.AuthToken = window.AuthToken;

    let requestLoad = JSON.stringify(request);

    return tools.XHR(
        "POST",
        window.API_HOST_SCHEMES,
        window.API_HOST_HOST,
        window.API_URL_UserInfo_SignUp,
        requestLoad
    );
};
